#include "widget.h"
#include "ui_widget.h"


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //添加条目
    ui->listWidget->addItem("java");
    ui->listWidget->addItem("c++");
    ui->listWidget->addItem("python");
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    //获取到输入框内容
    const QString& st=ui->lineEdit->text();
    //添加
    ui->listWidget->addItem(st);
}

void Widget::on_pushButton_2_clicked()
{
    //获取选中第几个
    int row=ui->listWidget->currentRow();
    if(row<0) return ;
    else ui->listWidget->takeItem(row);
}

void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if(current!=nullptr) qDebug()<<"当前选中元素为: "<< current->text();

    if(previous!=nullptr) qDebug()<<"上次选中元素为: "<< previous->text();
}
